package com.xopencode.comparable;

import java.util.Arrays;


/**
 * @author Mcb
 * @date 2022/6/19
 * @apiNote
 */
public class Demo {
    public static void main(String[] args) {
        System.out.println(Integer.compare(10,1));

        Product[] arr = new Product[6];
        arr[0] = new Product("A",59);
        arr[1] = new Product("A",69);
        arr[2] = new Product("A",79);
        arr[3] = new Product("B",12);
        arr[4] = new Product("C",44);
        arr[5] = new Product("D",102);

        Arrays.sort(arr);

        //Arrays.sort(arr, new Comparator<Product>() {
        //    @Override
        //    public int compare(Product o1, Product o2) {
        //        if (o1.getName().equals(o2.getName())){
        //            return Double.compare(o2.getPrice(),o1.getPrice());
        //        }else {
        //            return o1.getName().compareTo(o2.getName());
        //        }
        //    }
        //});   // 未实现Comparable接口会抛异常

        System.out.println(Arrays.toString(arr));
    }
}
